import request from '../network/request.js'

const  usedGoodsModule = {
	namespaced: true,
	
	actions : {
		// 上传二手物品
		addUsedGoodsInfo(miniStore, config){
			request({
				url: '/addUsedGoodsInfo',
				method: 'post',
				data: config.usedGoodsInfo,
				header: {
					"Authorization": "Bearer " + config.token
				}
			}).then(data => {
				if(data.status >= 200 && data.status < 300){
					uni.navigateBack(1)
					return
				}
			})
		},
		
		// 获取分类二手物品
		getClassificationUsedGoodsInfos(miniStore, config){
			request({
				url: '/getClassificationUsedGoodsInfos?articlesType=' + config.articlesType + '&size=' + config.size,
				method: 'get',
				header: {
					"Authorization": "Bearer " + config.token
				}
			}).then(data => {
				miniStore.state.classificationUsedGoodsInfos = data.classificationUsedGoodsInfos
			})
		},
		
		// 分页获取所有二手物品
		getUsedGoodsInfos(miniStore, config){
			request({
				url: '/getUsedGoodsInfos?size=' + config.size,
				method: 'get',
				header: {
					"Authorization": "Bearer " + config.token
				}
			}).then(data => {
				miniStore.state.usedGoodsInfos = data.usedGoodsInfos
			})
		},
		
		// 获取卖家基本信息
		getSellerInfo(miniStore, config){
			request({
				url: '/getSellerInfo?uId=' + config.uId,
				method: 'get',
				header: {
					"Authorization": "Bearer " + config.token
				}
			}).then(data => {
				miniStore.state.sellerInfo = data.sellerInfo
			})
		}
		
	},
	
	mutations: {
		// 删除二手物品
		deleteUsedGoods(state, value){
			
		},
		
		
	},
	
	state: {
		usedGoodsInfos: [],
		classificationUsedGoodsInfos: [],
		sellerInfo: {}
	},
	
	getter: {
		
	}
}

export default usedGoodsModule